<?php
/**
 * 
 * 评价管理信息
 * xysc users Version1.0
 * ==================================
 * Copy 2016-2017
 * Web:www.xjh7.com
 * ==================================
 * Author:xjh
 * Date:2016-05-07
 * model() 创建模型对象，静态
 * tableName() 返回表名
*/

class Eva extends CActiveRecord{
	/**
	 *返回当前模型对象的方法 
	 */
	public static function model($className = __CLASS__){
		return parent::model($className);
	}
	
	/**
	 * 返回当前表名
	 */
	public function tableName(){
		return '{{eva_content}}';
	}
	
	
	/**
	 * 根据goods_id和订单号查找评论
	 */
	public function getEvaContentByGoodsId($goods_id,$order_no){
		$cmodel = new CCCModel();
		$_sql = "SELECT b.user_name,a.content FROM {{eva_content}} a,{{user}} b  WHERE a.user_id=b.user_id AND a.goods_id=$goods_id AND a.order_no=$order_no";
		$row = $cmodel -> sel($_sql);
		return $row;
	}
	
	
	/**
	 * 发表评论
	 */
	public function addEvaContent($user_id,$order_no,$goods_id,$content){
		$cmodel = new CCCModel();
		$_sql = "INSERT INTO {{eva_content}}(`user_id`,`order_no`,`goods_id`,`content`,`eva_create_time`,`active`) VALUES($user_id,$order_no,$goods_id,'".$content."',".time().",1)";
		$row = $cmodel -> upd($_sql);
		return $row;
	}
	
	/**
	 * 检查是否已经评论过了
	 */
	public function CheckEva($user_id,$goods_id,$order_no){
		$cmodel = new CCCModel();
		$_sql = "SELECT * FROM {{eva_content}} a,{{order_details}} b WHERE b.order_status_id = 7 AND b.goods_id=a.goods_id AND b.order_no=$order_no  AND  a.goods_id=$goods_id AND a.user_id=$user_id";
		$row = $cmodel -> sel($_sql);
		return $row;
	}
	
	/**
	 * 更新订单状态
	 */
	public function updOrderStatus($goods_id,$order_no){
		$cmodel = new CCCModel();
		$_sql = "UPDATE  {{order_details}} set order_status_id =7  WHERE order_no = $order_no AND goods_id =  $goods_id";
		$row = $cmodel -> upd($_sql);
		return $row;
	}
	
	

}
	
?>